﻿using System;
using System.Linq;
using System.Collections.Generic;
using Apache.Cassandra;
using Sandy.Selectors;

namespace Sandy.Queries
{
    public class GetQuery
    {
        public static string Perform(SandyClient client, SandyFamily family, string key, string columnName)
        {
            ColumnPath path = new ColumnPath
            {
                Column_family = family.Name,
                Column = family.ColumnNameToBytes(columnName)
            };

            var result = client.Client.get(client.Keyspace, key, path, ConsistencyLevel.ONE);
            return family.GetValueString(result.Column.Value);
        }

        public static IDictionary<string, string> PerformSuper(SandyClient client, SandyFamily family, 
                                                               string key, string superCol)
        {
            ColumnPath path = new ColumnPath
                                  {
                                      Column_family = family.Name,
                                      Super_column = family.SuperColumnNameToBytes(superCol)
                                  };

            var result = client.Client.get(client.Keyspace, key, path, ConsistencyLevel.ONE);
            return family.CreateSupercolDict(result.Super_column);
        }

        public static string Perform(SandyClient client, SandyFamily family, string key, string superCol, 
                                     string column)
        {
            ColumnPath path = new ColumnPath
            {
                Column_family = family.Name,
                Super_column = family.SuperColumnNameToBytes(superCol),
                Column = family.ColumnNameToBytes(column)
            };

            var result = client.Client.get(client.Keyspace, key, path, ConsistencyLevel.ONE);
            return family.GetValueString(result.Column.Value);
           
        }
    }
}